package myJs.test

import myJs.api.Api
import myJs.assets.assetsCss
import myJs.cps.{Style}
import myJs.myPkg.ReactRouterDOM
import org.scalajs.dom.URLSearchParams
import slinky.core.FunctionalComponent
import slinky.core.annotations.react
import slinky.core.facade.Hooks.{useEffect, useState}
import slinky.web.html._
import typings.csstype.csstypeStrings
import myJs.Implicits._
import org.scalajs.dom.window.localStorage
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._

/**
 * Created by yz on 22/4/2022
 */
@react object TestCp {

  type Props = Unit

  private val css = List(
    assetsCss.Components,
    assetsCss.Login,
    assetsCss.BootstrapMin,
    assetsCss.My,
  )

  val component = FunctionalComponent[Props] { props =>

    val navigate = ReactRouterDOM.useNavigate()
    val location = ReactRouterDOM.useLocation()
    val searchParams = new URLSearchParams(location.search)
    val curId = searchParams.get("id").null2Empty

    val (account, setAccount) = useState("")
    val (password, setPassword) = useState("")
    val (info, setInfo) = useState("")
    val (id, setId) = useState(curId)

    object FTool {

      def passwordChange = (v: String) => {
        setPassword(v)
      }

      def accountChange = (v: String) => {
        setAccount(v)
      }

    }

    useEffect(() => {
      if (location.state != null) {
        val message = location.state.toJDJAn.myGet("message")
        setInfo(message)
      }
    }, List()
    )


    div(className := "login",

      div(className := "logo",
        div(style := Style(textAlign = csstypeStrings.center),
          h2(style := Style(textAlign = csstypeStrings.center, fontSize = "25px", color = "#0D2451"),
            img(style := Style(height = "50px"), src := s"${Api.images}/panda_logo_1.png"),
            " 样本管理系统"
          )
        )
      ),

      div(className := "content",
//        form(className := "login-form",
//          h3(className := "form-title", "登录"),
//
//          span(style := Style(lineHeight = "35px"), className := "error", info),
//
//          div(className := "form-group",
//            label(className := "control-label visible-ie8 visible-ie9", "用户名"),
//            PureInputCp(placeHolder = "用户名", value = account, onChange = FTool.accountChange)
//          ),
//          div(className := "form-group",
//            label(className := "control-label visible-ie8 visible-ie9", "密码"),
//            PureInputCp(placeHolder = "密码", `type` = "password", value = password, onChange = FTool.passwordChange)
//          ),
//        )
      ),

      div(className := "copyright",
        "版权所有2021 样品管理系统 All Rights Reserved"
      )

    )


  }

}
